﻿using System;
using System.Collections.Generic;
using System.Text;
using MYLSOFT.JsonSimple;

namespace com.byt.webcore.utils.tree
{
    public class Node : JSONObject
    {

        public JSONArray childs = null;
        public Node parent;
        public string labelChilds;

        public Node()
        {
            childs = new JSONArray();
            this.labelChilds = "childs";
        }

        public Node(string labelChilds)
        {
            childs = new JSONArray();
            this.labelChilds = labelChilds;
        }

        public Node Add(Node child)
        {
            if (childs.Count == 0)
            {
                if (!string.IsNullOrEmpty(labelChilds))
                    this.Add(labelChilds, childs);
            }
            child.parent = this;
            childs.Add(child);
            return child;
        }

        public JSONArray getChilds()
        {
            return childs;
        }

    }
}
